//
//  WBWelcomeViewController.swift
//  XLWibo-Swift
//
//  Created by 王林 on 2016/11/16.
//  Copyright © 2016年 木木. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage

//avatar_default_big
let magerBottom :CGFloat  = 120
class WBWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.backgroundColor = UIColor.cyan
        
        setupUI()
    }

  func setupUI (){
    self.view.addSubview(iconImgView)
    self.view.addSubview(lbl)
    
    iconImgView.snp.makeConstraints { (make) in
        make.bottom.equalTo(self.view).offset(-magerBottom)
        make.centerX.equalTo(self.view)
        make.size.equalTo(CGSize(width: 85, height: 85))
    }
    
    iconImgView.layer.cornerRadius = 85 * 0.5
    iconImgView.clipsToBounds = true
    iconImgView.sd_setImage(with: WBUserAccessViewModel.shared.headUrl)
    
    lbl.snp.makeConstraints { (make) in
        make.top.equalTo(iconImgView.snp.bottom).offset(20)
        make.centerX.equalTo(self.view)
    }
    lbl.alpha = 0
    
    
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        addAnimation()
    }
    
    let  H = -(UIScreen.main.bounds.height - magerBottom - 85)
    
    func  addAnimation(){
        
        
        UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 5, options: [], animations: {
            self.iconImgView.snp.updateConstraints({ (make) in
                make.bottom.equalTo(self.view).offset(self.H)
            })
            //更新约束
            self.view.layoutIfNeeded()
            
        }, completion:{(finished)->() in
            UIView.animate(withDuration: 1.0, animations: {
                self.lbl.alpha = 1
            }, completion: { (_)->() in
//                UIApplication.shared.keyWindow?.rootViewController = WBTarBarController()
                NotificationCenter.default.post(name: NSNotification.Name(KChangeRootViewController), object: nil)
            })
            
        })
        
    }
    
    
    lazy var iconImgView = UIImageView(image: #imageLiteral(resourceName: "avatar_default_big"))
    lazy var lbl = UILabel(title: "😝,欢迎回来", titleColor: UIColor.orange, font: UIFont.systemFont(ofSize: 16))
    

}
